package org.dtrd.config.wechat.entity.bean.officialaccount;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author qr
 * @date 2022/3/11 11:57
 */
@ApiModel("微信菜单")
@Getter
@Setter
@JsonInclude(JsonInclude.Include.NON_NULL)
public class WechatMenu {

    @ApiModelProperty(value = "一级菜单数组，个数应为1~3个", required = true)
    private List<WechatMenuButton> button;

    @ApiModelProperty("校验规则")
    private MatchRule matchrule;

    public WechatMenu(WechatMenuButton... buttons) {
        this.button = Arrays.stream(buttons).collect(Collectors.toList());
    }

    public WechatMenu(Integer tagId, WechatMenuButton... buttons) {
        if (tagId != null) {
            this.matchrule = new MatchRule(tagId);
        }
        this.button = Arrays.stream(buttons).collect(Collectors.toList());
    }

    @ApiModel("校验规则")
    @Getter
    @Setter
    @JsonInclude(JsonInclude.Include.NON_NULL)
    public static class MatchRule {

        @ApiModelProperty("用户标签的id，可通过用户标签管理接口获取")
        private Integer tag_id;

        @ApiModelProperty("客户端版本，当前只具体到系统型号：IOS(1), Android(2),Others(3)，不填则不做匹配")
        private Integer client_platform_type;

        public MatchRule(Integer tag_id) {
            this.tag_id = tag_id;
        }
    }
}
